package logic

import (
	"Junior_two/subject/usercenter/userrpc/internal/dao"
	"Junior_two/subject/usercenter/userrpc/model"
	"context"
	"time"

	"Junior_two/subject/usercenter/userrpc/internal/svc"
	"Junior_two/subject/usercenter/userrpc/pb/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRegLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegLogic {
	return &RegLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RegLogic) Reg(in *user.RegRequest) (*user.RegResponse, error) {
	// todo: add your logic here and delete this lin

	if !dao.RegInsert(&model.Users{
		Username:   in.Username,
		Password:   in.Password,
		Tel:        in.Mobile,
		Email:      "24764668464@163.com",
		UpdateTime: time.Now().Format(time.DateTime),
		CreateTime: time.Now().Format(time.DateTime),
	}) {
		return &user.RegResponse{
			Msg:  "注册失败",
			Code: 202,
		}, nil
	}

	return &user.RegResponse{
		Msg:  "注册成功",
		Code: 200,
	}, nil
}
